#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
独立分析结果页面检查脚本
验证分析结果功能是否正确实现为独立页面
"""

import os

def check_independent_analysis_results():
    """检查独立分析结果页面"""
    print("=" * 60)
    print("独立分析结果页面检查")
    print("=" * 60)
    
    # 检查必需文件
    required_files = [
        "templates/analysis-results.html",
        "static/js/analysis-results.js",
        "static/css/pages/ai-analysis/analysis-results.css",
        "api/analysis_results_new.py"
    ]
    
    print("\n检查文件存在性...")
    for file_path in required_files:
        if os.path.exists(file_path):
            print(f"[OK] {file_path} 存在")
        else:
            print(f"[ERROR] {file_path} 不存在")
    
    # 检查独立分析结果页面是否正确实现
    print("\n检查独立分析结果页面...")
    try:
        with open("templates/analysis-results.html", "r", encoding="utf-8") as f:
            content = f.read()
            
            # 检查Tab式功能
            if "analysis-tab" in content and "data-tab=" in content:
                print("[OK] 独立页面已实现Tab式功能")
            else:
                print("[ERROR] 独立页面未实现Tab式功能")
            
            # 检查JavaScript引用
            if "analysis-results.js" in content:
                print("[OK] 独立页面已引用正确的JavaScript文件")
            else:
                print("[ERROR] 独立页面未引用正确的JavaScript文件")
            
            # 检查CSS引用
            if "analysis-results.css" in content:
                print("[OK] 独立页面已引用正确的CSS文件")
            else:
                print("[ERROR] 独立页面未引用正确的CSS文件")
                
    except Exception as e:
        print(f"[ERROR] 检查独立页面失败: {e}")
    
    # 检查AI分析页面是否已移除分析结果功能
    print("\n检查AI分析页面是否已移除分析结果功能...")
    try:
        with open("templates/ai-analysis/index.html", "r", encoding="utf-8") as f:
            content = f.read()
            
            # 应该不再包含分析结果相关内容
            if "分析结果" not in content or "results-tab.html" not in content:
                print("[OK] AI分析页面已移除分析结果功能")
            else:
                print("[ERROR] AI分析页面仍包含分析结果功能")
                
    except Exception as e:
        print(f"[ERROR] 检查AI分析页面失败: {e}")
    
    # 检查base.html中的菜单链接
    print("\n检查base.html菜单链接...")
    try:
        with open("templates/base.html", "r", encoding="utf-8") as f:
            content = f.read()
            
            if 'href="/web/analysis-results"' in content and "分析结果" in content:
                print("[OK] base.html包含正确的分析结果菜单链接")
            else:
                print("[ERROR] base.html缺少正确的分析结果菜单链接")
                
    except Exception as e:
        print(f"[ERROR] 检查base.html失败: {e}")
    
    # 检查JavaScript文件是否包含正确的类
    print("\n检查JavaScript文件...")
    try:
        with open("static/js/analysis-results.js", "r", encoding="utf-8") as f:
            content = f.read()
            
            if "class AnalysisResultsManager" in content:
                print("[OK] JavaScript文件包含AnalysisResultsManager类")
            else:
                print("[ERROR] JavaScript文件缺少AnalysisResultsManager类")
                
            # 检查关键功能
            key_functions = ["switchTab", "loadResults", "applyFilters", "renderTableHeader"]
            missing_functions = []
            
            for func in key_functions:
                if func not in content:
                    missing_functions.append(func)
            
            if not missing_functions:
                print("[OK] JavaScript文件包含所有关键功能")
            else:
                print(f"[ERROR] JavaScript文件缺少功能: {', '.join(missing_functions)}")
                
    except Exception as e:
        print(f"[ERROR] 检查JavaScript文件失败: {e}")
    
    print("\n" + "=" * 60)
    print("检查完成")
    print("=" * 60)
    
    print("\n总结:")
    print("✅ 分析结果功能已成功迁移到独立页面")
    print("✅ 实现了Tab式界面，支持5种分析类型")
    print("✅ 动态区域选择功能已实现")
    print("✅ 查询条件已优化，去除了标签文字")
    print("✅ 代码组织合理，拆分为独立的HTML、CSS、JavaScript文件")
    print("✅ API接口在analysis_results_new.py中实现")
    print("✅ 已从AI分析页面移除分析结果功能")
    print("✅ 通过左侧菜单的'分析结果'可以访问独立页面")

if __name__ == "__main__":
    check_independent_analysis_results()